<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jqueryForm/jquery.form.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <select class="form-control" name="strategyId" >
                    <#list strategys as s>
                        <option value="${s.id}">${s.title}</option>
                    </#list>
                </select>
                <input type="submit" value="查询">
                <button type="button" class="btn-info inputBtn">添加</button>
            </form>
            <script>
                $("#searchForm select[name='strategyId']").val(${qo.strategyId})
            </script>
            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.name}</td>
                       <td>${entity.strategy.title}</td>
                       <td>${entity.sequence} </td>
                       <td>${entity.stateName}</td>
                        <td><a role="button" class="inputBtn" data-json='${entity.json}'>修改</a></td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="strategyModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">编辑攻略分类</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label" >所属攻略：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="strategy.id" >
                                <#list strategys as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                          <script>
                              $("#editForm select[name='strategy.id']").val(${qo.strategyId})
                          </script>
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-sm-4 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence">
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>


                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $(".inputBtn").click(function () {
            $("#editForm input").val("");
            var json = $(this).data("json");
            if (json) {
                $("#editForm input[name='id']").val(json.id)
                $("#editForm input[name='name']").val(json.name)
                $("#editForm input[name='sequence']").val(json.sequence)
                $("#editForm select[name='strategy.id']").val(json.strategy.id)
                $("#editForm select[name='state']").val(json.state.toString())
            }
            $("#strategyModal").modal("show")
        })

        $(".submitBtn").click(function () {
            $("#editForm").ajaxSubmit(function (data) {
                if (data.success) {
                    reload();
                }else{
                    $.messager.alert(data.msg);
                }
            })
        })
    })
</script>
</body>
</html>